public class Num12 {
    public static String intToRoman(int num) {
        String[] romans = new String[]{"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
        int[] values = new int[]{       1,  4,   5,   9,  10, 40,  50, 90, 100, 400,500, 900,1000};

        StringBuilder res = new StringBuilder();
        for (int i = values.length - 1; i >= 0; i--) {
            int temp = num/values[i];
            num -= temp * values[i];
            while(temp > 0){
                res.append(romans[i]);
                temp--;
            }
        }

        return res.toString();
    }

    public static void main(String[] args) {
        System.out.println(intToRoman(1994));
    }
}
